//
//  HLTabBarController.swift
//  MyBlog
//
//  Created by 李芙蓉 on 16/3/4.
//  Copyright © 2016年 hanlei. All rights reserved.
//

import UIKit

class HLTabBarController: UITabBarController {
    
    //在loadView中替换tabBarController的tabBar为自定义tabBar
    override func loadView() {
        
        super.loadView()
        
        let tabBar = HLTabBar()
        
        tabBar.composeCallBack = { (button:UIButton)->() in
            
            self.presentViewController(HLComposeController(), animated: true, completion: nil)
        }
        
        //tabBar为只读属性，通过KVC赋值
        self.setValue(tabBar, forKey: "tabBar")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewController(HLHomeController(), title: "主页", itemImageName: "tabbar_home")
        
        addChildViewController(HLMessageController(), title: "消息", itemImageName: "tabbar_message_center")
        
        addChildViewController(HLSearchController(), title: "发现", itemImageName: "tabbar_discover")
        
        addChildViewController(HLProfileController(), title: "我", itemImageName: "tabbar_profile")
    }

    //重载tabBarController的addChildViewControllers方法
    func addChildViewController(childController: UIViewController, title:String, itemImageName:String) {
        
        addChildViewController(HLTempNavigationController(rootViewController: childController))
        
        //设置标题
        childController.title = title
        
        //设置item图片
        childController.tabBarItem.image = UIImage(named: itemImageName)!.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置选中状态的item图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(itemImageName)_selected")!.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置高亮状态下的文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:myOrangeColor], forState: UIControlState.Selected)
    }
    
    //composeButton点击的闭包回调
}
